package com.ten.service.impl;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.ten.pojo.TotalResult;
import com.ten.service.HttpMessage;
import com.ten.utils.HttpClientUtil;
import com.ten.utils.MyDigestUtil;

/**
 * 
 * @author liujun
 *
 */
@Component
public class HttpMessageImpl implements HttpMessage{
	@Value("${appkey}")
	private  String appkey;
	@Value("${headUrl}")
	private  String headUrl;
	@Value("${areaCode}")
	private String areaCode;
	@Value("${appCode}")
	private String appCode;
	@Value("${groupCode}")
	private String groupCode;
	/**
	 * @author 刘军
	 */
	@Override
	public String getSpotsInfo(String groupCode) {
		Map<String,String> mapTree =new TreeMap<>();
		String url=headUrl+"getSpotsInfo.htm";
		 mapTree.put("groupCode", groupCode);
		 mapTree.put("appCode", appCode);
		 String sign =MyDigestUtil.md5Digest("groupCode="+groupCode);
		 mapTree.put("sign", sign);
		 String param =JSON.toJSONString(mapTree);
		 Map<String,String> map =new HashMap<>();
		 map.put("req_data", param);
		 String result =HttpClientUtil.doGet(url,map);
		 //System.out.println("result:"+result);
		 TotalResult tt= JSON.parseObject(result, TotalResult.class);
		 if("SUCCESS".equals(tt.getResult())){
			 return tt.getData();
		 }
		return "";
	}
	@Override
	public String getSpotsSaleInfo(String beginTime, String endTime, String parkFullName) {
		String url=headUrl+"getSpotsSaleInfo.htm";
		Map<String,String> mapTree =new TreeMap<>();
		mapTree.put("beginTime", beginTime);
		 mapTree.put("endTime", endTime);
		 mapTree.put("groupCode", groupCode);
		 mapTree.put("parkCode", parkFullName);
		 mapTree.put("appCode", appCode);
		 StringBuffer sb =new StringBuffer("");
		 sb.append("beginTime=");
		 sb.append(beginTime);
		 sb.append("&endTime=");
		 sb.append(endTime);
		 sb.append("&groupCode=");
		 sb.append(groupCode);
		 sb.append("&parkCode=");
		 sb.append(parkFullName);
		 String sign =MyDigestUtil.md5Digest(sb.toString());
		 mapTree.put("sign", sign);
		 String param =JSON.toJSONString(mapTree);
		 Map<String,String> map =new HashMap<>();
		 map.put("req_data", param);
		 String result =HttpClientUtil.doGet(url,map);
		 TotalResult tt= JSON.parseObject(result, TotalResult.class);
		 if("SUCCESS".equals(tt.getResult())){
			 return tt.getData();
		 }
		return "";
	}
	/**
	 * 
	 */
	@Override
	public String getSpotsCheckInfo(String beginTime, String endTime, String parkFullName) {
		 String url=headUrl+"getSpotsCheckInfo.htm";
		 Map<String,String> mapTree =new TreeMap<>();
		 mapTree.put("beginTime", beginTime);
		 mapTree.put("endTime", endTime);
		 mapTree.put("groupCode", groupCode);
		 mapTree.put("parkCode", parkFullName);
		 mapTree.put("appCode", appCode);
		 StringBuffer sb =new StringBuffer("");
		 sb.append("beginTime=");
		 sb.append(beginTime);
		 sb.append("&endTime=");
		 sb.append(endTime);
		 sb.append("&groupCode=");
		 sb.append(groupCode);
		 sb.append("&parkCode=");
		 sb.append(parkFullName);
		 //System.out.println("test:"+sb.toString());
		 String sign =MyDigestUtil.md5Digest(sb.toString());
		 mapTree.put("sign", sign);
		 String param =JSON.toJSONString(mapTree);
		 Map<String,String> map =new HashMap<>();
		 map.put("req_data", param);
		 String result =HttpClientUtil.doGet(url,map);
		 TotalResult tt= JSON.parseObject(result, TotalResult.class);
		 if("SUCCESS".equals(tt.getResult())){
			 return tt.getData();
		 }
		return "";
	}
	/**
	 * 统计接口
	 */
	@Override
	public String getStatInfo(String beginTime, String endTime) {
		 String url=headUrl+"getStatInfo.htm";
		 Map<String,String> mapTree =new TreeMap<>();
		 mapTree.put("beginTime", beginTime);
		 mapTree.put("endTime", endTime);
		 mapTree.put("groupCode", groupCode);
		 mapTree.put("appCode", appCode);
		 StringBuffer sb =new StringBuffer("");
		 sb.append("beginTime=");
		 sb.append(beginTime);
		 sb.append("&endTime=");
		 sb.append(endTime);
		 sb.append("&groupCode=");
		 sb.append(groupCode);
		 String sign =MyDigestUtil.md5Digest(sb.toString());
		 mapTree.put("sign", sign);
		 String param =JSON.toJSONString(mapTree);
		 Map<String,String> map =new HashMap<>();
		 map.put("req_data", param);
		 String result =HttpClientUtil.doGet(url,map);
		 //System.out.println("result:"+result);
		 TotalResult tt= JSON.parseObject(result, TotalResult.class);
		 if("SUCCESS".equals(tt.getResult())){
			 return tt.getData();
		 }
		return "";
	}
	/**
	 * 
	 */
	@Override
	public String getWebOrderInfo(String beginTime, String endTime) {
		 String url=headUrl+"getWebOrderInfo.htm";
		 Map<String,String> mapTree =new TreeMap<>();
		 mapTree.put("beginTime", beginTime);
		 mapTree.put("endTime", endTime);
		 mapTree.put("groupCode", groupCode);
		 mapTree.put("appCode", appCode);
		 StringBuffer sb =new StringBuffer("");
		 sb.append("beginTime=");
		 sb.append(beginTime);
		 sb.append("&endTime=");
		 sb.append(endTime);
		 sb.append("&groupCode=");
		 sb.append(groupCode);
		 String sign =MyDigestUtil.md5Digest(sb.toString());
		 mapTree.put("sign", sign);
		 String param =JSON.toJSONString(mapTree);
		 Map<String,String> map =new HashMap<>();
		 map.put("req_data", param);
		 String result =HttpClientUtil.doGet(url,map);
		 TotalResult tt= JSON.parseObject(result, TotalResult.class);
		 if("SUCCESS".equals(tt.getResult())){
			 return tt.getData();
		 }
		return "";
	}
	@Override
	public String getWebCheckInfo(String beginTime, String endTime) {
		String url=headUrl+"getWebCheckInfo.htm";
		Map<String,String> mapTree =new TreeMap<>();
		 mapTree.put("beginTime", beginTime);
		 mapTree.put("endTime", endTime);
		 mapTree.put("groupCode", groupCode);
		 mapTree.put("appCode", appCode);
		 StringBuffer sb =new StringBuffer("");
		 sb.append("beginTime=");
		 sb.append(beginTime);
		 sb.append("&endTime=");
		 sb.append(endTime);
		 sb.append("&groupCode=");
		 sb.append(groupCode);
		 String sign =MyDigestUtil.md5Digest(sb.toString());
		 mapTree.put("sign", sign);
		 String param =JSON.toJSONString(mapTree);
		 Map<String,String> map =new HashMap<>();
		 map.put("req_data", param);
		 String result =HttpClientUtil.doGet(url,map);
		 //System.out.println("result:"+result);
		 TotalResult tt= JSON.parseObject(result, TotalResult.class);
		 if("SUCCESS".equals(tt.getResult())){
			 return tt.getData();
		 }
		return "";
	}
	
	
	
	
	

}
